<template>
  <div class="pagination">
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[5, 10, 20, 30]"
      layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'

// 接收数据
const props = defineProps({
  currentPage: {
    type: Number,
    default: 1
  },
  pageSize: {
    type: Number,
    default: 5
  },
  total: {
    type: Number,
    default: 5
  }
})

const currentPage = ref(props.currentPage)
const pageSize = ref(props.pageSize)
// 传递
const emits = defineEmits(['update:currentPage', 'update:pageSize'])

// 一页显示多少条数据
const handleSizeChange = (page: number) => {
  pageSize.value = page
  emits('update:pageSize', page)
  //   pageSize.value = page
  //   emits('update:pageSize', page)
}

// 从一个页面切换到另一个页面的时候触发的事件
const handleCurrentChange = (page: number) => {
  currentPage.value = page
  emits('update:currentPage', page)
  //   currentPage.value = page
  //   emits('update:currentPage', page)
}
</script>

<style scoped>
.pagination {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
}
</style>
